<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\DB;
use Laravel\Passport\HasApiTokens;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
use App\Notifications\ResetPasswordNotification;
use Illuminate\Database\Eloquent\Model;
class CartoonRoles extends Authenticatable
{

    use HasApiTokens,Notifiable;


    protected $table = 'cartoon_role';

    protected $fillable = ['id','cartoon_id','member_id','characters_id','created_at'];

//    protected $hidden = ['password','remember_token'];
    public    $timestamps = 1;
    protected $primaryKey = 'id';
    /**
     * 返回用户数据
     * @param $id
     * @return mixed
     */
    public function getData($where){
        return self::where($where)
            ->first();
    }
    /**
     * 返回列表数据
     * @param $id
     * @return mixed
     */
    public function getList($where,$num,$orderBy1='id' , $orderBy2='desc')
    {
        return self::where($where)
            ->orderBy($orderBy1,$orderBy2)
            ->paginate($num)
            ->toArray();
    }
    /**
     * 返回列表数据
     * @param $id
     * @return mixed
     */
    public function getJoinList($where,$num,$orderBy1='id' , $orderBy2='desc')
    {
        return self::join('characters', 'cartoon_role.characters_id', '=', 'characters.id')->where($where)
            ->select('*','cartoon_role.id as id')
            ->orderBy($orderBy1,$orderBy2)
            ->paginate($num)
            ->toArray();
    }
    /**
     * 返回用户详细数据
     * @param $id
     * @return mixed
     */
    public function shows($id){

        return self::where(['id'=>$id])
            ->first();
    }
    public function role()
    {
        return $this->hasMany('App\Models\Character','id','characters_id');
    }

}
